<!DOCTYPE html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<div id="log"></div>
<textarea id="ta"></textarea>
<script>
test(function() {
    var ta = document.getElementById("ta");
    ta.value = "abc\n";
    ta.focus();
    ta.setSelectionRange(0, 4);
    document.execCommand("cut");
    document.execCommand("paste");
    assert_equals(ta.value, "abc\n");

    ta.setSelectionRange(0, 0);
    document.execCommand("paste");
    assert_equals(ta.value, "abc\nabc\n");
}, "Pasting text ending with newline should work correctly.");

test(function() {
    var source = document.createElement("textarea");
    document.body.appendChild(source);
    source.value = "\n";
    source.focus();
    source.select();
    document.execCommand("copy");

    var dest = document.createElement("textarea");
    document.body.appendChild(dest);
    dest.focus();
    document.execCommand("paste");
    assert_equals(dest.value, "\n");
    assert_equals(dest.selectionStart, 1);
    assert_equals(dest.selectionEnd, 1);
}, "Pasting \\n into an empty TEXTAREA should set the caret at the end.");
</script>
